36#define WOLF_STATE_BLOCK_CREATE(StateBlockClass) \
37 static StateBlockPtr create(const Eigen::VectorXd& _state, bool _fixed) \
39 return std::make_shared<StateBlockClass>(_state, _fixed); \
41 static StateBlockPtr createIdentity(bool _fixed) \
43 return std::make_shared<StateBlockClass>(StateBlockClass::Identity(), _fixed); \
50class LocalParametrizationBase;
72class StateBlock :
public std::enable_shared_from_this<StateBlock>
101 LocalParametrizationBasePtr _local_param_ptr =
nullptr,
102 bool _transformable =
true);
111 const Eigen::VectorXd& _state,
113 LocalParametrizationBasePtr _local_param_ptr =
nullptr,
114 bool _transformable =
true);
146 void setState(
const Eigen::VectorXd& _state,
const bool _notify =
true);
218 void setZero(
bool _notify =
true);
222 virtual Eigen::VectorXd
identity()
const;
226 Eigen::VectorXd
zero()
const;
231 void perturb(
double amplitude = 0.1);
260 void plus(
const Eigen::VectorXd& _dv);
277 const Eigen::VectorXd& _state,
279 LocalParametrizationBasePtr _local_param_ptr,
283 state_size_(_state.size()),
285 local_param_ptr_(_local_param_ptr),
286 state_updated_(false),
288 local_param_updated_(false),
289 transformable_(_transformable)
297 LocalParametrizationBasePtr _local_param_ptr,
302 state_(
Eigen::VectorXd::Zero(_size)),
303 local_param_ptr_(_local_param_ptr),
304 state_updated_(false),
306 local_param_updated_(false),
307 transformable_(_transformable)
366 assert(
local_param_ptr_ !=
nullptr &&
"state block without local parametrization");
373 assert(_local_param !=
nullptr &&
"setting a null local parametrization");
State block: a state vector of a variable of the nonlinear optimization.
Definition: state_block.h:73
StateBlock & operator=(const StateBlock &o)=delete
Not assignable.
StateBlock(StateBlock &&o)=delete
Not movable.
void perturb(double amplitude=0.1)
Perturbs the state (if not fixed) with random noise following a uniform distribution in [-amplitude,...
Definition: state_block.cpp:47
std::string getType() const
Returns the type of the state block.
Definition: state_block.h:317
bool localParamUpdated() const
Returns whether the local parametrization has been updated (to be notified to the solver)
Definition: state_block.h:388
Eigen::VectorXd zero() const
Returns the zero (identity) element of the state.
Definition: state_block.h:428
void resetStateUpdated()
Resets the state updated flag.
Definition: state_block.h:393
std::atomic_bool local_param_updated_
Flag to indicate whether the local parametrization has been updated.
Definition: state_block.h:87
std::string type_
Type of the derived class.
Definition: state_block.h:76
bool isFixed() const
Returns whether the state is fixed (not estimated)
Definition: state_block.h:339
bool isTransformable() const
Returns whether the state block can be transformed to another reference frame.
Definition: state_block.h:235
SizeEigen getSize() const
Returns the state size.
Definition: state_block.h:328
void unfix()
Sets the state as estimated.
Definition: state_block.h:349
virtual void setIdentity(bool _notify=true)
Sets the state to the identity element.
Definition: state_block.h:413
void resetFixUpdated()
Resets the fixed status updated flag.
Definition: state_block.h:398
bool transformable_
Flag to indicate if the state block can be transformed to another reference frame.
Definition: state_block.h:89
virtual void transform(const VectorComposite &_transformation)=0
Transforms the state to another reference frame (if transformable)
void setNonTransformable()
Sets the state block as not transformable to another reference frame.
Definition: state_block.h:249
bool isValid(double tolerance=Constants::EPS)
Returns whether the state is valid according to its local parametrization (e.g. unit quaternion)
Definition: state_block.h:433
bool stateUpdated() const
Returns whether the state has been updated (to be notified to the solver)
Definition: state_block.h:378
LocalParametrizationBasePtr getLocalParametrization() const
Returns the state local parametrization ptr.
Definition: state_block.h:359
std::atomic_bool state_updated_
Flag to indicate whether the state has been updated or not.
Definition: state_block.h:85
void plus(const Eigen::VectorXd &_dv)
Adds a (tangent) increment to the state, through the local parametrization if any.
Definition: state_block.cpp:56
void setState(const Eigen::VectorXd &_state, const bool _notify=true)
Sets the state vector.
Definition: state_block.cpp:25
std::mutex mut_state_
State vector mutex.
Definition: state_block.h:81
Eigen::VectorXd getState() const
Returns the state vector.
Definition: state_block.h:322
StateBlock(const std::string &_type, const SizeEigen _size, bool _fixed=false, LocalParametrizationBasePtr _local_param_ptr=nullptr, bool _transformable=true)
Constructor from size.
Definition: state_block.h:294
void setZero(bool _notify=true)
Sets the state to zero (the identity element)
Definition: state_block.h:418
virtual Eigen::VectorXd identity() const
Returns the identity element of the state.
Definition: state_block.h:423
void fix()
Sets the state as fixed.
Definition: state_block.h:344
SizeEigen getLocalSize() const
Returns the size of the local parametrization.
Definition: state_block.h:333
virtual ~StateBlock()
Destructor.
Definition: state_block.h:312
void setLocalParametrization(LocalParametrizationBasePtr _local_param)
Sets a local parametrization.
Definition: state_block.h:371
StateBlock(const StateBlock &o)=delete
Not copyable.
void setTransformable(bool _trf=true)
Sets whether the state block can be transformed to another reference frame.
Definition: state_block.h:242
Eigen::VectorXd state_
State vector storing the state values.
Definition: state_block.h:80
LocalParametrizationBasePtr local_param_ptr_
Local parametrization (optimization in the tangent space)
Definition: state_block.h:83
void removeLocalParametrization()
Removes the state_block local parametrization.
Definition: state_block.h:364
bool fixUpdated() const
Returns whether the fixed status has been updated (to be notified to the solver)
Definition: state_block.h:383
void setFixed(bool _fixed)
Sets the state status.
Definition: state_block.cpp:38
std::atomic_bool fix_updated_
Flag to indicate whether the status has been updated or not.
Definition: state_block.h:86
void resetLocalParamUpdated()
Resets the local parametrization updated flag.
Definition: state_block.h:403
std::atomic< SizeEigen > state_size_
State vector size.
Definition: state_block.h:79
double * getStateData()
Returns the state vector data array.
Definition: state_block.h:408
std::atomic_bool fixed_
Flag to indicate whether the state is fixed or not.
Definition: state_block.h:77
bool hasLocalParametrization() const
Returns whether the state has a local parametrization.
Definition: state_block.h:354
Composite of state vectors.
Definition: vector_composite.h:29
Namespace extending Eigen definitions.
Definition: wolf.h:91
const double EPS
Definition: wolf.h:74
Definition: capture_base.h:23
EIGEN_DEFAULT_DENSE_INDEX_TYPE SizeEigen
Vector and Matrices size type for the Wolf project.
Definition: wolf.h:58